//app.js
App({
  onLaunch: function () {
    var that = this;
    // 展示本地存储能力
    tt.checkSession({
      success(res) {
        var userInfo = tt.getStorageSync('userInfo');
        var open_id = tt.getStorageSync('open_id');
        var unionid = tt.getStorageSync('unionid');
        var token = tt.getStorageSync('token');
        console.log(token);
        if (token) {
          that.globalData.toutiaoInfo = userInfo;
          that.globalData.open_id = open_id;
          that.globalData.unionid = unionid;
          that.globalData.token = token;
        } else {
          that.logout(function () { });
          // tt.removeStorageSync('userInfo');
          // tt.removeStorageSync('open_id');
          // tt.removeStorageSync('token');
          // tt.removeStorageSync('unionid');
        }

      },
      fail(res) {
        that.logout(function () { });
        // tt.removeStorageSync('userInfo');
        // tt.removeStorageSync('open_id');
        // tt.removeStorageSync('token');
        // tt.removeStorageSync('unionid');
      }
    });

  },

  logout: function (fn) {
    // tt.removeStorage({
    //   key: 'userInfo',
    //   success(res) {
    //     tt.removeStorage({
    //       key: 'token',
    //       success(res) {
    //         fn();
    //       },
    //       fail(res) {
    //         console.log(`removeStorage调用失败`);
    //       }
    //     });
    //   },
    //   fail(res) {
    //     console.log(`removeStorage调用失败`);
    //   }
    // });
    tt.removeStorageSync('userInfo');
    tt.removeStorageSync('open_id');
    tt.removeStorageSync('token');
    tt.removeStorageSync('unionid');
    this.globalData.token = '';
    this.globalData.toutiaoInfo = '';
    fn();

  },
  globalData: {
    url: 'http://mishu.tangxiaojie.com/api/',
    // url:'http://192.168.16.66/toutiao/BaQiDeTangXiaoJieXiangMu/mishu.tangxiaojie.com/api/',
    appid: 'tt3d6a4bd7a24085ae',
    toutiaoInfo: null, //用户登录的微信信息
    memberInfo: null, //用户的网站信息
    systemInfo: null,
    token: '', //用户token
    open_id: '',
    unionid: '',
    is_login: 0
  }
})